<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no"/>
<base th:href="${#request.getContextPath()}+'/'">
<link rel="stylesheet" href="css/ydui.css" type="text/css"/>
<link rel="stylesheet" href="css/demo.css" type="text/css"/>
<link href="css/reset.css" rel="stylesheet" type="text/css">
<link href="css/receiving-adress.css" rel="stylesheet" type="text/css">
<script src="js/ydui.flexible.js"></script>
</head>
<body>
<div class="near-box">
	<div class="header">
		<a href="javascript:history.go(-1)" class="left"></a>
		收货地址
	</div>
	<div class="bigbox">
		 <div class="receiv-text1">地址信息</div>
         <div class="receiv-box1"><input type="text" id="realName" class="receiv-input1" placeholder="收货人姓名（请使用真实姓名）"></div>
         <div class="receiv-box1"><input type="number" id="mobile" class="receiv-input1" placeholder="手机号码"></div>
         <div class="delivery-layer-box">
    		<div class="cell-item">
                <div class="cell-right cell-arrow">
                    <input type="text"  class="cell-input" readonly id="J_Address" placeholder="请选择收货地址">
                </div>
            </div>
	    </div>
         <div class="receiv-box2"><textarea id="address2" class="receiv-input2" placeholder="详细地址"></textarea></div>
         <button class="set-text1">保存</button>
	</div>

</div>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/ydui.citys.js"></script>
<script type="text/javascript" src="js/ydui.js"></script>
<script type="text/javascript" src="js/core.util.js"></script>
<script type="text/javascript" src="js/mlayer.min.js"></script>
<script type="text/javascript">
	/**
 * 默认调用
 */
!function () {
	var $target = $('#J_Address');

	$target.citySelect();

	$target.on('click', function (event) {
		event.stopPropagation();
		$target.citySelect('open');
	});

	$target.on('done.ydui.cityselect', function (ret) {
		$(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
	});
}();

$(function() {
    var addressId = CoreUtil.getQueryVariable("addressId");
    var memberId = CoreUtil.getQueryVariable("memberId");
    CoreUtil.sendPost("/api/user/getMemberAddressInfo", {"id":addressId}, function (res) {
        if (res.code == 200) {
            $("#realName").val(res.data.realName);
            $("#mobile").val(res.data.mobile);
        } else {
            mlayer.error({
                title: res.msg,
                time: 3
            });
        }
    });

    $(".set-text1").click(function() {
        var realName = $("#realName").val();
        if(CoreUtil.isEmpty(realName ,'收货人不能为空')) {
            return;
        }
        var mobile = $("#mobile").val();
        if(CoreUtil.isEmpty(mobile ,'收货人不能为空')) {
            return;
        }
        var address1 = $("#J_Address").val();
        if(CoreUtil.isEmpty(address1 ,'收货地址不能为空')) {
            return;
        }
        var address2 = $("#address2").val();
        if(CoreUtil.isEmpty(address2 ,'详细地址不能为空')) {
            return;
        }
        var address = address1 + address2;

        CoreUtil.sendPost("/api/user/updateMemberAddress", {"realName" : realName, "address" : address, "mobile" : mobile, "id":addressId}, function (res) {
            if (res.code == 200) {
                location.href="receiving-adress-list.html?memberId=" + memberId;
            } else {
                mlayer.error({
                    title: res.msg,
                    time: 3
                });
            }
        });
    });

});
</script>
</body>
</html>